import { makeAutoObservable } from 'mobx'
import { client } from '@/utils'
import { gql } from '@apollo/client'
import { message } from 'antd'
const RESERVATION_INPUT = gql`
mutation CreateReservation($reservationInput: ReservationInput!) {
  createReservation(reservationInput: $reservationInput) {
    arrivalDate
    arrivalTime
    tableSize
    name
    phone
    status
    createdAt
    id
  }
}
`
const GET_RESERVATIONS = gql`
query GetReservation($phone: String) {
  getReservation(phone: $phone) {
    arrivalTime
    arrivalDate
    tableSize
    name
    phone
    status
    createdAt
  }
}
`
class ReservationStore {
  constructor() {
    makeAutoObservable(this)
  }
  GET_RESERVATIONS = GET_RESERVATIONS
  reservations = []
  createReservation = async (arrivalDate, arrivalTime, tableSize) => {
    try {
      const res = await client.mutate({
        mutation: RESERVATION_INPUT,
        variables: {
          reservationInput: {
            arrivalDate,
            arrivalTime,
            tableSize
          }
        }
      })
      message.success('预约成功！')
      return res
    } catch (error) {
      message.error(error.message)
    }
  }
}
export default ReservationStore